package com.tnr.scgcxx.controller.safty;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.tnr.scgcxx.model.Role;
import com.tnr.scgcxx.model.User;
import com.tnr.scgcxx.service.safty.HomeService;
import com.tnr.scgcxx.service.safty.RoleService;
import com.tnr.scgcxx.service.safty.UserService;

@Controller
@RequestMapping("/safty")
public class SaftyView {
	
	@Resource
	private HomeService homeService;
	
	@Resource
	private UserService userService;
	
	@Resource
	private RoleService roleService;
	
	@RequestMapping("/home_to")
	public String homeTo(Model model) {
		
		//List<MenuDto> menuList =homeService.getMenus();
		
		//model.addAttribute("mainList", menuList);
		
		return "safty/home";
	}
	
	@RequestMapping("/login_to")
	public String loginTo() {
		
		return "safty/login";
		
	}
	
	@RequestMapping(value="/role_to",method=RequestMethod.GET)
	public String roleTo() {
		return "safty/role";
	}
	
	@GetMapping("/role_add_to")
	public String roleAddTo() {
		return "safty/role_add";
	}
	
	@GetMapping("/role_upd_to")
	public String roleUpdTo(String ro_id,Model model) {
		Role ro=roleService.getRole(ro_id);
		model.addAttribute("ro", ro);
		return "safty/role_upd";
	}
	
	@RequestMapping(value="/user_to",method=RequestMethod.GET)
	public String userTo() {
		return "safty/user";
	}
	
	@GetMapping("/user_add_to")
	public String userAddTo() {
		return "safty/user_add";
	}
	
	@GetMapping("/user_upd_to")
	public String userUpdTo(String u_id,Model model) {
		User u=userService.getUser(u_id);
		model.addAttribute("u", u);
		return "safty/user_upd";
	}
	
}
